package com.neteast.androidclient.newscenter.util;

import java.security.MessageDigest;

import android.util.Log;

public class MD5Util {
	/**
	 * 生成和php的md5兼容的md5字符串
	 * @param password
	 * @return
	 */
	public static String phpMD5Encode(String value){
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
    	    md.update(value.getBytes());    	    
    	    StringBuffer buf=new StringBuffer(); 
    	    final byte[] data=md.digest();
    	    final int N=data.length;
    	    for(int i=0;i<N;i++){
    	    	byte b=data[i];
    	    	buf.append(String.format("%02x", b&0xff) );    
    	    }
    	    return buf.toString();
		} catch (Exception e) {
			Log.e("test", e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e);
		}
	}
}
